<%-- 
    Document   : GetInfo
    Created on : Sep 30, 2011, 11:52:11 PM
    Author     : James
--%>

<%@page import="java.util.List"%>
<%@page import="EntityState.*"%>
<%@page import="BusinessLogic.Constants"%>
<%@page import="java.util.ArrayList"%>
<%@page import="servlet.Cart"%>
<%@ page contentType="text/xml" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<getInfo>
<%
    ArrayList data = (ArrayList) request.getAttribute("data");
    int result = ((Integer) data.get(0)).intValue();
    if (result == Constants.STATUS_SESSION_EXPIRED) {
%>
<status>SESSION_EXPIRED</status>
<%
   } else if (result == Constants.STATUS_INVALID_INPUT) {
%>
<status>INVALID_INPUT</status>
<%
   } else if (result == Constants.STATUS_NOT_FOUND) {
%>
<status>NOT_FOUND</status>
<%
   } else if (result == Constants.STATUS_SUCCESSFUL) {
%>
<status>SUCCESSFUL</status>
<%
       int action = Integer.parseInt(request.getParameter("action"));
       if (action == Constants.GET_LIST_OF_PARTNER_CATEGORIES) {
%>
<categories>
<%
           List<ItemCategoryState> categories = (List<ItemCategoryState>) data.get(1);
           for (ItemCategoryState ics : categories) {
%>
    <category>
        <catID><%= ics.getId() %></catID>
        <catName><%= ics.getName() %></catName>
<%
                for (ItemState is : ics.getListOfItems()) {
%>
        <item>
            <itemID><%= is.getId() %></itemID>
            <itemName><%= is.getName() %></itemName>
        </item>
<%
               } 
%>
    </category>
<%
           }
%>
</categories>
<%
       } else if (action == Constants.GET_LIST_OF_OUTLETS) {
%>
<outlets>
<%
           List<OutletState> outlets = (List<OutletState>) data.get(1);
           for (OutletState os : outlets) {
%>
    <outlet>
        <id><%= os.getId() %></id>
        <name><%= os.getName() %></name>
    </outlet>
<%
           }
%>
</outlets>
<%
       } else if (action == Constants.GET_LIST_OF_OUTLET_ITEMS) {
%>
<items>
<%
           List<ItemState> items = (List<ItemState>) data.get(1);
           for (ItemState is : items) {
              
%>
    <anItem>
        <id><%= is.getId() %></id>
        <name><%= is.getName() %></name>
    </anItem>
<%
           }
%>
</items>
<%
       } else if (action == Constants.GET_RESERVABLE_UNIT_INFO) { 
           ReservableUnitState rus = (ReservableUnitState) data.get(1);
           ReservableUnitDetailsState details = rus.getLatestReservableUnitDetails();
           FileState layout  = rus.getLayout();
           int minimumLength = details.getReservableMinimumLength();
           int maximumLength = details.getReservableMaximumLength();
           int minimumLead   = details.getReservationMinimumLeadTime();
           int maximumLead   = details.getReservationMaximumLeadTime();
%>
<unit>
    <minimumLength><%= minimumLength %></minimumLength>
    <maximumLength><%= maximumLength %></maximumLength>
    <minimumLead><%= minimumLead %></minimumLead>
    <maximumLead><%= maximumLead %></maximumLead>
    <unitInfo><![CDATA[
        <table class="white">
            <tr>
                <td>Reserved Item</td>
                <td>
                    <%
                        ItemState reservedItem = rus.getReservedItem();
                        if (reservedItem == null) out.print(rus.getName());
                        else out.print("<a href='CustGetItemInfo?action="+ Constants.GET_DETAILED_ITEM_INFO + "&id=" + reservedItem.getId() + "'>" + reservedItem.getName() + "</a>");
                    %>
                </td>
            </tr>
            <tr>
                <td>No show fee</td>
                <td><%= details.getReservationNoShowFee() %></td>
            </tr>
            <tr>
                <td>Cancel fee</td>
                <td><%= details.getReservationCancelFee() %></td>
            </tr>
            <tr>
                <td>Duration allowed</td>
                <td>
                    <%
                        double min, max;
                        String minUnit = " hour(s)", maxUnit = " hour(s)";
                        if (minimumLength == maximumLength || maximumLength == 0) {
                            min = minimumLength / (double) 60;
                            if (min > 24) {
                                minUnit = " day(s)";
                                min = min / (double) 24;
                            }    
                            if (maximumLength == 0) out.println(min + minUnit + " or more");
                            else out.print(min + minUnit);
                        } else {
                            min = minimumLength / (double) 60;
                            max = maximumLength / (double) 60;
                            if (min > 24) {
                                minUnit = " day(s)";
                                min = min / (double) 24;
                            }
                            if (max > 24) {
                                maxUnit = " days(s)";
                                max = max / (double) 24;
                            }
                            out.print(min + minUnit + " to " + max + maxUnit);
                        }
                    %>
                </td>
            </tr>
            <tr>
                <td>Lead time</td>
                <td>
                    <%
                        minUnit = " hour(s)"; 
                        maxUnit = " hour(s)";
                        if (maximumLead == 0) {
                            min = minimumLength / (double) 60; 
                            if (min > 24) {
                                minUnit = " day(s)";
                                min = min / (double) 24;
                            }
                            out.print(min + minUnit + " or more");
                                                           
                        } else {
                            min = minimumLength / (double) 60;
                            max = maximumLength / (double) 60;
                            if (min > 24) {
                                minUnit = " day(s)";
                                min = min / (double) 24;
                            }
                            if (max > 24) {
                                maxUnit = " days(s)";
                                max = max / (double) 24;
                            }
                            out.print(min + minUnit + " to " + max + maxUnit);
                        }
                    %>
                </td>
            </tr>
            <%
                if (layout != null) {
            %>
            <tr>
                <td>Layout</td>
                <td><img src="<%= layout.getLocation() %>" /></td>
            </tr>
            <%
                }
                int i = 0;
                for (FileState fs : rus.getListOfPictures()) {
                    i++;
            %>
            <tr>
                <td>Picture <%= i %></td>
                <td><img src="<%= fs.getLocation() %>" /><br/><%= fs.getDescription() %></td>
            </tr>
            <%
                }
            %>
        </table>
    ]]></unitInfo>
    <userInfo><![CDATA[
        <table class="white">
            <%
                if (minimumLength == maximumLength) {
            %>
            <tr>
                <td>Date</td>
                <td><input type="text" name="date" /></td>
            </tr>
            <tr>
                <td>Time</td>
                <td>
                    <select id="hour1" name="hour1"><option value="">Hour</option>
                        <option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option>
                        <option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option>
                        <option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option>
                        <option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
                        <option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
                        <option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option>
                    </select>
                    :
                    <select id="minute1" name="minute1"><option value="">Minute</option>
                        <option value="0">00</option>
                        <option value="30">30</option>
                    </select>
                </td>
            </tr>
            <%
                } else {
            %>
            <tr>
                <td>Start date</td>
                <td><input type="text" id="date1" /></td>
            </tr>
            <tr>
                <td>Start time</td>
                <td>
                    <select id="hour1"><option value="">Hour</option>
                        <option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option>
                        <option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option>
                        <option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option>
                        <option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
                        <option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
                        <option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option>
                    </select>
                    :
                    <select id="minute1"><option value="">Minute</option>
                        <option value="0">00</option>
                        <option value="30">30</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>End date</td>
                <td><input type="text" id="date2" /></td>
            </tr>
            <tr>
                <td>End time</td>
                <td>
                    <select id="hour2"><option value="">Hour</option>
                        <option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option>
                        <option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option>
                        <option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option>
                        <option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
                        <option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
                        <option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option>
                    </select>
                    :
                    <select id="minute2"><option value="">Minute</option>
                        <option value="0">00</option>
                        <option value="30">30</option>
                    </select>
                </td>
            </tr>
            <%
                }
            %>
            <tr>
                <td>Number of People</td>
                <td><input type="text" id="numOfPeople" name="numOfPeople" /></td>
            </tr>
            <tr>
                <td>Contact name</td>
                <td><input type="text" id="name" name="name" /></td>
            </tr>
            <tr>
                <td>Contact no.</td>
                <td>+<input type="text" id="countryCode" name="countryCode" /> - <input type="text" id="phone" name="phone" /></td> 
            </tr>
        </table>
    ]]></userInfo>
</unit>
<%
       }
    }
%>
</getInfo>